package com.donn.securitycontrolplatform.common.controller;

import com.dahuatech.icc.exception.ClientException;
import com.donn.securitycontrolplatform.common.Result;
import com.donn.securitycontrolplatform.common.service.CommonService;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@Tag(name = "CommonController", description = "通用请求处理Controller")
@Slf4j
@RequestMapping("/scp/api/common")
public class CommonController {

    @PostMapping("/download")
    @ApiOperation(value = "通用下载文件")
    public void fileDownload(String fileName, Boolean delete, HttpServletResponse response,
                             HttpServletRequest request) {
        String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf('_') + 1);
        try {
        } catch (Exception e) {
            log.error("下载文件失败", e);
        }
    }

    @Autowired
    CommonService commonService;

    /**
     * 通用上传文件接口
     *
     * @param multipartFile 文件
     * @return 上传结果
     */
    @ResponseBody
    @PostMapping(value = "/upload")
    public Result upload(@RequestParam("file") MultipartFile multipartFile) {
        return commonService.upload(multipartFile);
    }

    /**
     * 人脸布控消息订阅
     */
    @ResponseBody
    @PostMapping(value = "/face/msg")
    public void receiveFaceMsg(@RequestBody String body) throws ClientException {
        commonService.receiveFaceMsg(body);
    }


    /**
     * 门禁消息订阅
     */
    @ResponseBody
    @PostMapping(value = "/mj/msg")
    public void receiveMjMsg(@RequestBody String body) throws ClientException {
        commonService.receiveMjMsg(body);
    }

}
